#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: tpf_modules.py 
@version:
@time: 2022/05/06 
"""
from TapClientCore.T05_TM_feature.v2.TMF07_modules.tmf_modules import TMFModules
from TapUtil.decorator.some_useful import timeout


class TPFModules(TMFModules):

    # 创建
    def create_api_publish(self, connection_id, api_name, table_name, fields):
        try:
            self.pending_modules_api_server_by_name(api_name)
            self.delete_modules_api_server_by_name(api_name)
        finally:
            return self.create_api_server(connection_id, api_name, table_name, fields)

    # 激活
    def active_api_publish(self, api_name):
        return self.active_modules_api_server_by_name(api_name)

    # 停止
    def pending_api_publish(self, api_name):
        return self.pending_modules_api_server_by_name(api_name)

    # 删除
    def delete_api_publish(self, api_name):
        return self.delete_modules_api_server_by_name(api_name)

    # 查询
    def query_api_publish(self, api_name):
        return self.get_modules_api_server_by_name(api_name)

    # 等待 api server status 为running
    @timeout('running', 12)
    def wait_api_server_running(self):
        return self.get_api_serve_status()
